# -*- coding: utf-8 -*-
# @Time : 2021/9/10 18:21
# @Author : 伟哥
# @Email : xw@gmail.com
# @File : tianjia_shangji_page.py
# @Project : crm
'''添加商机页面的定位器以及操作方法'''
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from utils.util import HOST
from page.base_page import BasePage
from utils.table import table
from utils.Echo_defs.test_random import GBK2312
class BianJi(BasePage):
    '''编辑商机页面的定位器以及操作方法'''

    #定位器
    url="{}/index.php?m=business&a=edit&id=92".format(HOST)
    fzr_locator = (By.CSS_SELECTOR, "#owner_name")
    fzr_table_locator = (By.CSS_SELECTOR, "#d_content")
    yeshu_locator=(By.CSS_SELECTOR,"#total_pages")
    fzr_queren_locator = (By.XPATH, '/html/body/div[11]/div[3]/div/button[1]')
    kehu_locator = (By.CSS_SELECTOR, '#customer_name')
    kehu_table_locator = (By.CSS_SELECTOR, "#datas")
    kehu_queren_locator = (By.XPATH, "/html/body/div[8]/div[3]/div/button[1]")
    jine_locator = (By.CSS_SELECTOR, "#total_price")
    shangji_name_locator = (By.CSS_SELECTOR, '#name')
    lianxiren_locator = (By.CSS_SELECTOR, '#contacts_name')
    lianxiren_xz_locator = (By.XPATH, '//*[@id="data2"]/tr[1]/td[1]/input')
    lianxiren_queren_locator = (By.XPATH, '/html/body/div[10]/div[3]/div/button[1]')
    shengfen_locator = (By.NAME, "contract_address['state']")
    shi_locator = (By.NAME, "contract_address['city']")
    qu_locator = (By.NAME, "contract_address['area']")
    jie_locator = (By.CSS_SELECTOR, 'input[placeholder="街道信息"]')
    shangjileixing_locator = (By.CSS_SELECTOR, "#type")
    zhuangtai_locator = (By.CSS_SELECTOR, '#status_id')
    shangjilaiyuan_locator = (By.CSS_SELECTOR, "#origin")
    yingdanlv_locator = (By.CSS_SELECTOR, "#gain_rate")
    yuqijiage_locator = (By.CSS_SELECTOR, '#estimate_price')
    xiacilianxi_time_locator = (By.CSS_SELECTOR, '#nextstep_time')
    xiacilianxi_leirong_locator = (By.CSS_SELECTOR, '#nextstep')
    beizhu_locator = (By.CSS_SELECTOR, '#description')
    baocuen_locator=(By.CSS_SELECTOR,'[value="保存"]')


    def fzr(self,fzr):
        '''根据输入的负责人，选择负责人'''
        self.driver.find_element(*self.fzr_locator).click()
        num=int(self.driver.find_element(*self.yeshu_locator).text)
        table(self.driver,self.fzr_table_locator,num,fzr,1)
        self.driver.find_element(*self.fzr_queren_locator).click()



    def kehu(self,kehu):
        '''根据输入的客户选择客户'''
        self.driver.find_element(*self.kehu_locator).click()
        sleep(2)
        num=self.driver.find_element(*self.yeshu_locator).text
        num = int(num)
        table(self.driver, self.kehu_table_locator, num, kehu, 1)
        self.driver.find_element(*self.kehu_queren_locator).click()



    def jine(self,jine):
        '''输入商机金额'''
        element=self.driver.find_element(*self.jine_locator)
        element.clear()
        element.send_keys(jine)

    def shangjiming(self,name=None):
        '''输入商机名'''
        element=self.driver.find_element(*self.shangji_name_locator)
        element.clear()
        self.driver.switch_to.alert.accept()
        if name:
            element.send_keys(name)
        else:
            element.send_keys(GBK2312())

    def lianxiren(self,lianxiren=None):
        '''选择联系人'''
        self.driver.find_element(*self.lianxiren_locator).click()
        self.driver.find_element(*self.lianxiren_xz_locator).click()
        self.driver.find_element(*self.lianxiren_queren_locator).click()


    def sheng(self,num=1):
        '''选择省'''
        shengfen_element = self.driver.find_element(*self.shengfen_locator)
        select = Select(shengfen_element)
        select.select_by_index(num)

    def shi(self,num=1):
        '''选择市'''
        shi_element = self.driver.find_element(*self.shi_locator)
        select = Select(shi_element)
        select.select_by_index(num)

    def qu(self,num=1):
        '''选择区'''
        qu_element = self.driver.find_element(*self.qu_locator)
        select = Select(qu_element)
        select.select_by_index(num)

    def jie(self,jie):
        '''输入街'''
        element = self.driver.find_element(*self.jie_locator)
        element.clear()
        element.send_keys(jie)

    def leixiong(self,num=1):
        '''选择商机类型'''
        shangjileixing_element = self.driver.find_element(*self.shangjileixing_locator)
        select = Select(shangjileixing_element)
        select.select_by_index(num)

    def zhuangtai(self,num=1):
        '''选择状态'''
        zhuangtai_element = self.driver.find_element(*self.zhuangtai_locator)
        select = Select(zhuangtai_element)
        select.select_by_index(num)

    def laiyuan(self,num=1):
        '''选择来源'''
        shangjilaiyuan_element = self.driver.find_element(*self.shangjilaiyuan_locator)
        select = Select(shangjilaiyuan_element)
        select.select_by_index(num)

    def yingdanlv(self,ydl):
        '''输入赢单lv'''
        element=self.driver.find_element(*self.yingdanlv_locator)
        element.clear()
        element.send_keys(ydl)

    def yuqijiage(self,yqjg):
        '''输入预期价格'''
        element=self.driver.find_element(*self.yuqijiage_locator)
        element.clear()
        element.send_keys(yqjg)

    def xiacilianxishijian(self,shijian):
        '''输入下次联系时间'''
        element=self.driver.find_element(*self.xiacilianxi_time_locator)
        element.clear()
        element.send_keys(shijian)

    def xiacilianxileirong(self,neirong):
        '''输入联系内容'''
        element=self.driver.find_element(*self.xiacilianxi_leirong_locator)
        element.clear()
        element.send_keys(neirong)

    def beizhu(self,bz='商务部门对接'):
        '''输入备注'''
        element=self.driver.find_element(*self.beizhu_locator)
        element.clear()
        element.send_keys(bz)

    def baocuen(self):
        '''点击保存'''
        self.driver.find_element(*self.baocuen_locator).click()